import React, { useEffect, useState } from "react";
import { get_synthesis } from "@/api/emr/index";
import { BasicForm, useForm } from "@/components/Form";
import "./index.less";
export default function emr() {
	const [synthesisList, setSynthesisList] = useState({
		nameEn: "",
		blocks: []
	});
	const [schemas, setSchemas] = useState([]);
	const [formContent] = useForm({
		schemas,
		showActionButtonGroup: false,
		labelWidth: 150,
		baseColProps: { span: 12 }
	});
	const getBlock = () => {
		return synthesisList.blocks.map((item: any) => {
			return (
				<div key={item.blockId}>
					<h3>{item.nameCn}</h3>
					<BasicForm layout="vertical" register={formContent}></BasicForm>
				</div>
			);
		});
	};
	// let rrr = {

	// };
	useEffect(() => {
		const get_list = async () => {
			// 获取接口数据
			const res = await get_synthesis({ fromId: "2" });
			setSynthesisList(res);
			// 获取FORM的schemas
			let arr: any = [];
			res.blocks.map((item: any) => {
				item.subjects.map((v: any) => {
					arr.push({
						label: v.nameCn,
						field: v.subjsId,
						component: "Input"
					});
				});
			});
			setSchemas(arr);
		};
		get_list();
	}, []);
	return (
		<div className="page block overflow-auto">
			<div className="header">
				<div className="text-center font-size-9">调查问卷</div>
				<div className="text-center font-size-5">{synthesisList.nameCn}</div>
				{getBlock()}
			</div>
		</div>
	);
}
